<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" labelAlign="right" :labelCol="{ style: 'width: 100px' }" @keyup.enter.native="searchQuery">
        <a-row :gutter="10">
          <a-col :md="5" :sm="24">
            <a-form-item label="起始时间">
              <a-date-picker v-model="queryParam.startTime" :disabled-date='disabledStartDate' style="width:100%" valueFormat="YYYY-MM-DD HH:mm:ss"
                :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }" />
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="24">
            <a-form-item label="终止时间">
              <a-date-picker v-model="queryParam.endTime" :disabled-date='disabledEndDate' style="width:100%" valueFormat="YYYY-MM-DD HH:mm:ss"
                :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }" />
            </a-form-item>
          </a-col>
          <!-- <a-col :md="5" :sm="24">
            <a-form-item label="报警位置">
                <a-select v-model="alarmLocations" mode="multiple" :show-arrow='true' placeholder="请选择报警位置" @change="alarmLocationChange">
                  <a-select-option value="SYS">站台</a-select-option>
                  <a-select-option value="UP">上行</a-select-option>
                  <a-select-option value="DOWN">下行</a-select-option>
              </a-select>              
            </a-form-item>
          </a-col> -->
          <a-col :md="5" :sm="24">
            <a-form-item label="报警位置">
              <a-tree-select
                v-model="locations"
                style="width: 100%"
                class="treeSelect"
                :tree-data="equipData"
                tree-checkable
                :show-checked-strategy="SHOW_CHILD"
                placeholder="请选择报警位置"
                :maxTagCount='0'
                :dropdownStyle="{height:'280px'}"
                :show-arrow='true'
                @change="alarmDeviceCodesChange"
              />                
            </a-form-item>
          </a-col>  
          <a-col :md="5" :sm="24">
            <a-form-item label="报警级别">
              <a-select placeholder="请选择报警级别" v-model="alarmLevels" mode="multiple" :show-arrow='true' @change="alarmLevelChange">
                <a-select-option value="一级">故障</a-select-option>
                <a-select-option value="二级">报警</a-select-option>
                <!-- <a-select-option value="三级">三级</a-select-option> -->
              </a-select>
            </a-form-item>
          </a-col>                  

          <!-- <a-col :md="5" :sm="24">
            <a-form-item label="设备类型">
              <a-input placeholder="请输入设备类型" v-model="queryParam.faultTypeCode"></a-input>
            </a-form-item>
          </a-col> -->
          <!-- <a-col :md="5" :sm="24">
            <a-form-item label="故障类型">
              <a-select placeholder="请选择故障类型" v-model="queryParam.faultId">
                <a-select-option v-for='e in faultTypeList' :key="e.id" :value="e.id">{{e.faultTypeName}}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="24">
            <a-form-item label="处理状态">
              <a-select placeholder="请选择处理状态" v-model="queryParam.status">
                <a-select-option :value="0">未处理</a-select-option>
                <a-select-option :value="1">已处理</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>           -->
          <a-col :md="4" :sm="24">
            <span class="table-page-search-submitButtons" >
              <a-button type="primary" @click="searchQuery">查询</a-button>
              <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
              <!-- <a @click="advanced=!advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'" />
              </a> -->
            </span>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <!-- <a-col :md="5" :sm="24">
            <a-form-item label="部件类型">
              <a-input placeholder="请输入部件类型" v-model="queryParam.faultTypeCode"></a-input>
            </a-form-item>
          </a-col> -->
          <!-- <a-col :md="5" :sm="24">
            <a-form-item label="报警类型">
              <a-select v-model="queryParam.alarmCategory" placeholder="请选择报警类型">
                <a-select-option  value="DEVICE_FAULT">设备报警</a-select-option >
                <a-select-option  value="PARTS_FAULT">部件报警</a-select-option >
              </a-select>  
            </a-form-item>
          </a-col> -->

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('设备故障报警')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>-->
      <!-- 高级查询区域 -->
      <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query> -->
      <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table ref="table" size="middle" :scroll="{ x: true }" bordered rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading"
         class="j-table-force-nowrap" @change="handleTableChange">
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <span slot="alarmCategory" slot-scope="text">
          {{text=='DEVICE_FAULT'?'设备报警':'部件报警'}}
        </span>
        <span slot="status" slot-scope="text">
          <span v-if='text==0' style="color:#b52d2d">未处理</span>
          <span v-else style="color:#99d276">已处理</span>
        </span>

        <span slot="alarmLevel" slot-scope="text">
          {{text=='一级'?'故障':'报警'}}
        </span>

        <span slot="action" slot-scope="text, record">
          <!-- <a @click="handleEdit(record)">编辑</a> -->

          <!-- <a-divider type="vertical" /> -->
          <a @click="handleDetail(record)">详情</a>
          <!-- <a-divider type="vertical" /> -->
          <!-- <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm> -->
        </span>
      </a-table>
    </div>

    <!-- <gd-device-fault-alarm-modal ref="modalForm" @ok="modalFormOk"></gd-device-fault-alarm-modal> -->
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import GdDeviceFaultAlarmModal from './modules/GdDeviceFaultAlarmModal'
import { getAction } from '@/api/manage'
import { TreeSelect } from 'ant-design-vue';
const SHOW_CHILD = TreeSelect.SHOW_CHILD;
import moment from 'moment';

export default {
  name: 'GdDeviceFaultAlarmList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    GdDeviceFaultAlarmModal,
  },
  data() {
    return {
      description: '设备故障报警管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '报警时间',
          align: 'center',
          dataIndex: 'alarmTime',
          width:'260px'
          // customRender: function (text) {
          //   return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          // },
        }, 
        {
          title: '报警位置',
          align: 'center',
          dataIndex: 'alarmLocation',
        },    
        {
          title: '报警编号',
          align: 'center',
          dataIndex: 'alarmDeviceCode',
        },                   
        {
          title: '报警级别',
          align: 'center',
          dataIndex: 'alarmLevel',
          scopedSlots: { customRender: 'alarmLevel' }
        },        
        // {
        //   title: '报警类型',
        //   align: 'center',
        //   dataIndex: 'alarmCategory',
        //   scopedSlots: { customRender: 'alarmCategory' },
        // },

        {
          title: '报警名称',
          align: 'center',
          dataIndex: 'faultType',
        },
        // {
        //   title: '故障类型',
        //   align: 'center',
        //   dataIndex: 'faultType',
        // },
        // {
        //   title: '处理状态',
        //   align: 'center',
        //   dataIndex: 'status',
        //   scopedSlots: { customRender: 'status' },
        // },

        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/fault/gdDeviceFaultAlarm/list',
        delete: '/fault/gdDeviceFaultAlarm/delete',
        deleteBatch: '/fault/gdDeviceFaultAlarm/deleteBatch',
        exportXlsUrl: '/fault/gdDeviceFaultAlarm/exportXls',
        importExcelUrl: 'fault/gdDeviceFaultAlarm/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
      advanced:false,
      faultTypeList:[],
      equipData:[],
      SHOW_CHILD,
      alarmLocations:[],
      locations:[],
      alarmLevels:[],
      queryParam:{
       alarmTime:moment().format("YYYY-MM-DD HH:mm:ss")
      }
    }
  },
  created() {
    // this.dataSource=[{id:1,alarmDeviceName:'mock'},{id:2,alarmDeviceName:'mock'}]
    this.getFaultTypeList()
    this.getEquipData(); //编号
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
      disabledStartDate(startValue) {
        // const endValue = this.form.endTime;
        // if (!startValue || !endValue) {
        //   return false;
        // }
        // return startValue.valueOf() > moment(endValue).valueOf();
        return startValue.valueOf() > moment().valueOf();
      },
      disabledEndDate(endValue) {
        // const startValue = this.form.startTime;
        // if (!endValue || !startValue) {
        //   return false;
        // }
        // return  moment(startValue).valueOf() >= endValue.valueOf();
        return endValue.valueOf() > moment().valueOf();

      },    
    moment,
    initDictConfig() { },
    getFaultTypeList(){
      getAction('/fault/gdDeviceFaultType/listAll').then(e=>{
        if(e && e.code == 200) {
          console.log('故障类型列表==》》', this.faultTypeList)
          this.faultTypeList= e.result
        }
      })
    },
    handleDetail(data) {
      this.$router.push({path:'/fault/faultWarningList/Detail',query:{id:data.id}})
    },
    alarmLocationChange(value){
      this.queryParam.alarmLocations = value.join(',')
    },
    alarmDeviceCodesChange(val){
      this.queryParam.locations = val.join(',')
    },
    alarmLevelChange(val) {
      this.queryParam.alarmLevels = val.join(',')
    },
    searchReset(){
      this.queryParam={
        alarmTime:'',
        alarmLocations:'',
        locations:'',
        alarmLevels:'',
      }
      this.alarmLocations=[]
      this.locations=[]
      this.alarmLevels=[]
    }     
  },
}
</script>
<style scoped lang="less">
@import '~@assets/less/common.less';
  .treeSelect {
    /deep/.ant-select-selection--multiple .ant-select-selection__choice{
      visibility: hidden;
    }
    /deep/.ant-select-search__field {
      visibility: hidden;
    }
  }
</style>